package com.example.brazil_project.function;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


























import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.os.Bundle;
import android.app.Activity;
import android.app.Notification;
import android.app.Notification.Builder;
import android.app.NotificationManager;
import android.app.PendingIntent;

import com.example.brazil_project.Arrive_CabinetActivity;
import com.example.brazil_project.Arrive_air_trsActivity;
import com.example.brazil_project.DucumentActivity;
import com.example.brazil_project.GeneralizeIndexActivity;
import com.example.brazil_project.LoginActivity;
import com.example.brazil_project.MainActivity;
import com.example.brazil_project.MsgActivity;
import com.example.brazil_project.OpinionActivity;
import com.example.brazil_project.PhotographArrActivity;
import com.example.brazil_project.RedactDocumentDetailActivity;
import com.example.brazil_project.Sales_promotionActivity;
import com.example.brazil_project.UserInfoActivity;
import com.example.brazil_project.WatchfulImporterActivity;
import com.example.brazil_project.parameter.Parameter;
import com.example.brazil_project.util.HttpUtil;
import com.example.brazil_project.util.JSFunction;
import com.example.brazil_project.util.SharedPreferencesUtil;
import com.example.brazil_project.util.jsonUtil;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.webkit.WebView;
import android.widget.Toast;

public class Public_method {
	 Activity mContxt; 
	 Object view;

	public Public_method(Activity mContx) {  
	        this.mContxt = mContx;  
	        this.view = view;  
	        Parameter.openingContx = mContx;
//	        webview = (WebView) view;
	  }  
	
	
	public void set_w_h(double w ,double h){		
		//Toast.makeText(mContxt, "w:"+w+"#h:"+h, 1000).show();
		SharedPreferences sp = mContxt.getSharedPreferences("window_w_h", mContxt.MODE_PRIVATE);
		SharedPreferences.Editor editor = sp.edit(); 
		//用putString的方法保存数据
		editor.putString("width", w+"");
		editor.putString("height",h+""); 
		editor.commit(); 
	
	}
	
public String get_w_h(){
	SharedPreferences sharedPreferences= mContxt.getSharedPreferences("window_w_h",mContxt.MODE_PRIVATE);
	// 使用getString方法获得value，注意第2个参数是value的默认值
	String width =sharedPreferences.getString("width", "0");
	String height =sharedPreferences.getString("height", "0"); 
	Map map = new HashMap();
	map.put("width", width);
	map.put("height", height);
	
	String a = jsonUtil.getJsonbymap(map);
	//Toast.makeText(mContxt, a, 1000).show();
	return a;
	
	}
   /**关闭当前Activity*/
	public void finishActivity(){
		
		mContxt.finish();
	}
	
	/**跳转主页*/
	public void gotoMain(){
		
		Intent intent = new Intent(mContxt, MainActivity.class);
		 mContxt.startActivity(intent);
		 
	}
	
	/**跳转到注册页面*/
	public void gotoLogin(){
		
		Intent intent = new Intent(mContxt, LoginActivity.class);
		 mContxt.startActivity(intent);
		 
	}
	
	/**跳转到产品修改页面*/
	public void gotoRedact(String id){
		
		Intent intent = new Intent(mContxt, RedactDocumentDetailActivity.class);
		intent.putExtra("du_id",id);
		mContxt.startActivity(intent);
		 
	}
	//查看用户详情
	public void gotoUserInfo(String username){
		Intent intent = new Intent(mContxt, UserInfoActivity.class);
		intent.putExtra("username",username);
		mContxt.startActivity(intent);
		
	}
	
	/**头部菜单栏跳转**/
	public void gotoMenu(String menu){
		//到货单拍照
		if(menu.equals("photographArr")){
			Intent intent = new Intent(mContxt, PhotographArrActivity.class);
			mContxt.startActivity(intent);
		}
		
		//消息页面
		if(menu.equals("msg")){
			Intent intent = new Intent(mContxt, MsgActivity.class);
			mContxt.startActivity(intent);
		}
		//我的产品
		if(menu.equals("mydocu")){
			Intent intent = new Intent(mContxt, DucumentActivity.class);
			String name = getLoginUserName();
			intent.putExtra("username", name);
			mContxt.startActivity(intent); 
		}
		//到空运
		if(menu.equals("arrive")){
			Intent intent = new Intent(mContxt, Arrive_air_trsActivity.class);
			intent.putExtra("username", getLoginUserName());
			mContxt.startActivity(intent);
		}
		//到新柜
		if(menu.equals("newdocu")){
			Intent intent = new Intent(mContxt, Arrive_CabinetActivity.class);
			intent.putExtra("username", getLoginUserName());
			mContxt.startActivity(intent);
		}
		
		//推广
		if(menu.equals("generalize")){
			Intent intent = new Intent(mContxt, GeneralizeIndexActivity.class);
			intent.putExtra("username", getLoginUserName());
			mContxt.startActivity(intent);
		}
		//促销
		if(menu.equals("promotion")){
			Intent intent = new Intent(mContxt, Sales_promotionActivity.class);
			intent.putExtra("username", getLoginUserName());
			mContxt.startActivity(intent);
		}
		//建议反馈
		if(menu.equals("suggest")){
			Intent intent = new Intent(mContxt, OpinionActivity.class);
			mContxt.startActivity(intent);
			}
		//个关注的人
		if(menu.equals("importer")){
			Intent intent = new Intent(mContxt, WatchfulImporterActivity.class);
			intent.putExtra("username", getLoginUserName());
			mContxt.startActivity(intent);
		}
		
	}
	
	//根据用户名跳转到用户的产品库
	 public void gotoMyProduct(String username){
		 Intent intent = new Intent(mContxt, DucumentActivity.class);
			String name = getLoginUserName();
			intent.putExtra("username", username);
			mContxt.startActivity(intent); 
	 }
	
	/**
	 * 获取js返回值
	 * @return
	 */
	public void getJsReturn(String returnValue){
		Parameter.getJsReturn = "";
		Parameter.getJsReturn = returnValue;
	}
	
	
	/**
	 * 获取提醒信息
	 * @return
	 */
	public String getMSG(){
		return Parameter.alertMSG ;
	}
	  

	/**
	 * 设置提醒信息
	 * @return
	 */
	public void setMSG(String msg){
		
		Parameter.alertMSG= msg; 
		if(msg.equals("")){
			Parameter.alertMSG=null;
		}
		
	}
	
	/**
	 * 根据用户名返回用户资料信息
	 * @param userName 用户名
	 * @return 用户资料信息
	 */
	public String getUserProfileByUserName(String userName){
		 String url = Parameter.getServerPath()+"APP/user/getUserProfile.nut?userName="+userName;
	 	 String msg = HttpUtil.doPost(url);
	 	 
	 	 
	 	 //本地保存用户角色
	 	 Map map = jsonUtil.getMapForJson(msg);
	 	 if(map.get("userName").equals(getLoginUserName())){
	 		 Map map1 = new HashMap();
	 		 map1.put("userType", map.get("userType"));
	 		 SharedPreferencesUtil.setSharedPreferencesData(mContxt, "u_p", map1);
	 	 }
		return msg;
		
	}
	
	/**
	 * 获取当前登录人的用户名
	 * @return
	 */
	public String getLoginUserName(){
		 List list = new ArrayList();
		 list.add("username");
		 Map <String,String> map =  SharedPreferencesUtil.getSharedPreferencesData(mContxt, "u_p", list) ;
			String  username = map.get("username");
			//如果有保存账号密码
			 if(username!=null && username.length()>0){
			
				System.out.println(username);
				return username;
				
			 }
		return null;
	}
	
	/**
	 * 获取当前登录人的密码
	 * @return
	 */
	public String getLoginUserpassword(){
		 List list = new ArrayList();
		 list.add("password");
		 Map <String,String> map =  SharedPreferencesUtil.getSharedPreferencesData(mContxt, "u_p", list) ;
		 String  password = map.get("password");
		 
			//如果有保存账号密码
		 	if(password!=null && password.length()>0){
				
					return password;
			 }
				return null;
	}
	/**
	 * 获取当前登录人的角色
	 * @return
	 */
	public String getLoginUserType(){
		 List list = new ArrayList();
		 list.add("userType");
		 Map <String,String> map =  SharedPreferencesUtil.getSharedPreferencesData(mContxt, "u_p", list) ;
		 String  userType = map.get("userType");
		 
			//如果有保存账号密码
		 	if(userType!=null && userType.length()>0){
				
					return userType;
			 }
				return null;
	}
	/**
	 * 获取服务器访问地址
	 * @return
	 */
	public String getServerPath(){
		return Parameter.getServerPath();
	}
	
	 /**
	  * 退出登录
	  */
	 public void exit(){
		 Map map1 = new HashMap();
		 map1.put("password", null);
		 SharedPreferencesUtil.setSharedPreferencesData(mContxt, "u_p", map1);
		 gotoMain();
		 
	 }
	 /**
	  * 根据参数名，获取上个acticity传过来的值
	  * @param Paramatename
	  * @return
	  */
	 public String getThisActivityParamate(String Paramatename){
		 Intent intent = mContxt.getIntent();
		  Paramatename = intent.getStringExtra(Paramatename);
		
		return Paramatename;
		 
	 }
	
}
